#!/bin/bash

cd ~/server-tools/alpha/stacks
git pull

read -p "aid download? [Y/n] " response
if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then
    echo "NOT download aid."
else
    bash ../aid_download.sh
fi

# if [ ! -d "stacks" ]; then
#     read -p "clone stacks"
#     git clone https://atomgit.com/ntlv1/stacks.git
#     cd stacks
# else
#     cd stacks
#     git pull
# fi

# read -p "data restore? [Y/n] " response
# if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then
#     echo "NOT restore data."
# else
#     bash ~/server-tools/common/backres/data-restore.sh
# fi

# read -p "aid restore? [Y/n] " response
# if [[ "$response" =~ ^([nN][oO]|[nN])$ ]]; then
#     echo "NOT restore aid."
# else
#     bash ~/server-tools/common/backres/aid-restore.sh
# fi

read -p "docker login aliyun vpc"
docker login registry.cn-zhangjiakou.aliyuncs.com

read -p "caddy"
cd caddy
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
if [ ! -e /aid/caddy ]; then
    bash get-permissions.sh
fi
docker compose up -d
cd ..

read -p "frps"
cd frps
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
if [ ! -e /aid/frps ]; then
    bash get-permissions.sh
fi
docker compose up -d
cd ..

read -p "grafana"
cd grafana
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
docker compose up -d
cd ..

read -p "prometheus"
cd prometheus
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
if [ ! -e /aid/prometheus ]; then
    bash get-permissions.sh
fi
docker compose up -d
cd ..

read -p "node-exporter"
cd node-exporter
bash get-image.sh
docker compose up -d
cd ..

read -p "kanboard"
cd kanboard
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
docker compose up -d
cd ..

read -p "firefly_iii"
cd firefly_iii
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
docker compose up -d
cd ..

read -p "lobe-chat"
cd lobe-chat
bash get-image.sh
docker compose up -d
cd ..

read -p "kosync"
cd kosync
bash get-image.sh
bash ~/server-tools/common/backres/aid-extract.sh
docker compose up -d
cd ..

echo "Docker deploy finish!"
# cd ~
